//
//  ABCViewController.m
//  ABCAppearanceKit
//
//  Created by Joe on 08/30/2022.
//  Copyright (c) 2022 Joe. All rights reserved.
//

#import "ABCViewController.h"
#import "NSObject+ABCDynamic.h"
#import "ABCDynamicManager.h"
#import "ABCViewController1.h"

@interface ABCViewController ()

@property (nonatomic, strong) UIButton *button1;

@property (nonatomic, strong) UIButton *button2;

@property (nonatomic, strong) UIButton *button3;

@property (nonatomic, strong) UIWindow *window;

@end

@implementation ABCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [self.view abc_bindDynamicUpdate:^(ABCAppearanceDynamicStyle dynamicStyle) {
        if (dynamicStyle == ABCAppearanceDynamicStyle_Light) {
            self.view.backgroundColor = [UIColor whiteColor];
        }else {
            self.view.backgroundColor = [UIColor blackColor];
        }
        
    }];
    
    self.button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button1 setTitle:@"是否跟随系统:   否" forState:UIControlStateNormal];
    self.button1.backgroundColor = [UIColor redColor];
    
    
    self.button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button2 setTitle:@"白天模式" forState:UIControlStateNormal];
    self.button2.backgroundColor = [UIColor greenColor];
    
    
    self.button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button3 setTitle:@"暗黑模式" forState:UIControlStateNormal];
    self.button3.backgroundColor = [UIColor blueColor];
    
    [self.view addSubview:self.button1];
    [self.view addSubview:self.button2];
    [self.view addSubview:self.button3];
    
    [self.button1 addTarget:self action:@selector(doEvent1) forControlEvents:UIControlEventTouchUpInside];
    [self.button2 addTarget:self action:@selector(doEvent2) forControlEvents:UIControlEventTouchUpInside];
    [self.button3 addTarget:self action:@selector(doEvent3) forControlEvents:UIControlEventTouchUpInside];
    
    self.button1.frame = CGRectMake(0, 100, 100, 50);
    self.button2.frame = CGRectMake(0, 200, 100, 50);
    self.button3.frame = CGRectMake(0, 300, 100, 50);
    
    [self changestatus];
    
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.frame = CGRectMake(0, 0, 100, 100);
    imageView.center = self.view.center;
    imageView.image = [UIImage imageNamed:@"111"];
    [self.view addSubview:imageView];
    
    UIWindow *window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    window.layer.cornerRadius = 50;
    window.layer.masksToBounds = YES;
    window.rootViewController = [[ABCViewController1 alloc]init];
    window.windowLevel = UIWindowLevelAlert + 1;
    [window makeKeyAndVisible];
//    window.hidden = YES;
    self.window = window;
    
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(200, 100, 100, 50)];
    textField.backgroundColor = [UIColor redColor];
    [self.view addSubview:textField];
    
}

- (void) doEvent1 {
    ABCDynamicManager.isUpdateFollowSystem = !ABCDynamicManager.isUpdateFollowSystem;
    [self changestatus];
}

- (void)changestatus {
    self.button2.hidden = ABCDynamicManager.isUpdateFollowSystem;
    self.button3.hidden = ABCDynamicManager.isUpdateFollowSystem;
    [self.button1 setTitle:ABCDynamicManager.isUpdateFollowSystem ? @"是否跟随系统:   是" :  @"是否跟随系统:   否" forState:UIControlStateNormal];
    self.button2.backgroundColor = ABCDynamicManager.currentDynamicStyle == ABCAppearanceDynamicStyle_Light ? [UIColor greenColor] : [UIColor brownColor];
    self.button3.backgroundColor = ABCDynamicManager.currentDynamicStyle == ABCAppearanceDynamicStyle_Dark ? [UIColor blueColor] : [UIColor brownColor];
}

- (void) doEvent2 {
    ABCDynamicManager.currentDynamicStyle = ABCAppearanceDynamicStyle_Light;
    [self changestatus];
}

- (void) doEvent3 {
    ABCDynamicManager.currentDynamicStyle = ABCAppearanceDynamicStyle_Dark;
    [self changestatus];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
